package com.ruoyi.project.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.Districts;
import com.ruoyi.project.system.service.IDistrictsService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 地区管理Controller
 * 
 * @author sangkf
 * @date 2020-02-26
 */
@RestController
@RequestMapping("/system/districts")
public class DistrictsController extends BaseController
{
    @Autowired
    private IDistrictsService districtsService;

    /**
     * 查询地区管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:districts:list')")
    @GetMapping("/list")
    public TableDataInfo list(Districts districts)
    {
        startPage();
        List<Districts> list = districtsService.selectDistrictsList(districts);
        return getDataTable(list);
    }

    /**
     * 导出地区管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:districts:export')")
    @Log(title = "地区管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Districts districts)
    {
        List<Districts> list = districtsService.selectDistrictsList(districts);
        ExcelUtil<Districts> util = new ExcelUtil<Districts>(Districts.class);
        return util.exportExcel(list, "districts");
    }

    /**
     * 获取地区管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:districts:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(districtsService.selectDistrictsById(id));
    }

    /**
     * 新增地区管理
     */
    @PreAuthorize("@ss.hasPermi('system:districts:add')")
    @Log(title = "地区管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Districts districts)
    {
        return toAjax(districtsService.insertDistricts(districts));
    }

    /**
     * 修改地区管理
     */
    @PreAuthorize("@ss.hasPermi('system:districts:edit')")
    @Log(title = "地区管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Districts districts)
    {
        return toAjax(districtsService.updateDistricts(districts));
    }

    /**
     * 删除地区管理
     */
    @PreAuthorize("@ss.hasPermi('system:districts:remove')")
    @Log(title = "地区管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(districtsService.deleteDistrictsByIds(ids));
    }
}
